#pragma once

#include <gtl/thread/locker.h>

namespace gtl
{

class semaphore
{
	semaphore(const semaphore&);
	semaphore& operator=(const semaphore&);

public:
	semaphore(int count = 1, const tchar* name = NULL)
	{
		m_semaphore = CreateSemaphore(NULL, count, count, name);
	}

	~mutex()
	{
		unlock();
		CloseHandle(m_semaphore);
	}

public:
	void lock()
	{
		WaitForSingleObject(m_semaphore, INFINITE);
	}

	void unlock()
	{
		ReleaseSemaphore(m_semaphore, 1, NULL);
	}

protected:
	HANDLE m_semaphore;
};


} // end of namespace gtl